package main

import (
	"fmt"
	"log"

	"github.com/go-xorm/xorm"
	_ "github.com/lib/pq"
)

const (
	host     = "localhost"
	port     = 5432
	user     = "admin"
	password = "admin"
	dbname   = "test"
)

type Product struct {
	Code  string
	Price uint
}

var engine *xorm.Engine

func main() {
	//https://www.kancloud.cn/kancloud/xorm-manual-zh-cn/
	psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)
	var err error
	engine, err = xorm.NewEngine("postgres", psqlInfo)
	defer engine.Close()

	if err != nil {
		log.Panicln(err)
	} else {
		log.Println("fasf")
	}
	//	product := Product{Code: "naefar", Price: 13414}
	product := new(Product)
	product.Code = "myname"
	product.Price = 12312
	affected, err := engine.Insert(product)
	// INSERT INTO user (name) values (?)
	log.Println(affected)

}
